// pages/index/withdraw/withdraw.js
let network = require('../../../utils/requestManager.js')
let app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    err_msg: "错误信息",
    win_height: '',
    discount_num: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      win_height: app.globalData.winHeight,
      discount_num: app.globalData.offline_discount,
    })
  },

  //获取折扣
  bind_discount:function(e){
    let value = e.detail.value;
    if(value > 9.5){
      wx.showToast({
        title: '折扣需在0.1-9.5之间',
        icon: 'none',
        duration: 2000
      });
      if(value > 9.5){
        this.setData({
          discount_num: 9.5
        });
      }
    } else {
      this.setData({
        discount_num: value
      });
    }
  },

  //提交请求
  request_data:function(){
    let that = this;
    console.log(that.data.discount_num)
    network.postRequest('backend/shop/v1/shop/api/seller/shop_info/offline_discount/update',{
      offline_discount: that.data.discount_num*10
    },function(res){
      console.log(res);
      if(res.status == 0){
        getApp().globalData.offline_discount = res.detail.offline_discount / 10;
        wx.navigateBack({
          delta:1
        });
      } else {
        wx.showModal({
          title: '提示',
          content: res.detail,
        })
      }
      // wx.showToast({
      //   title: '设置成功',
      //   icon:'success',
      //   success:function(){
      //     wx.navigateBack({
      //       delta:1
      //     })
      //   }
      // })
    })
  },

  //点击修改折扣
  set_discount:function(){
    let that = this;
    that.request_data()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})